package com.demo.convert.tool;

import java.io.File;
import java.net.MalformedURLException;
import java.util.Objects;

/**
 * @author fenggang.li
 * @create 2019-09-12 10:19
 */
public class FileTool {
    /**
     * Check whether the parent folder of this file exists.<br/>
     *
     * @param filePath
     * @return true, if folder exists; false, otherwise.
     */
    public static boolean checkParentFolder(String filePath) {
        if (Objects.isNull(filePath)) {
            return false;
        }
        File file = new File(filePath);
        File parentFile = file.getParentFile();
        boolean exists = parentFile.exists();
        return exists;
    }

    public static String toUrl(String filePath) throws MalformedURLException {
        String url = new File(filePath).toURI().toURL().toString();
        return url;
    }
}
